<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约挂号 - 医疗预约系统</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <style>
        .header {
            background-color: #2c3e50;
            color: white;
            padding: 20px 0;
            margin-bottom: 30px;
        }
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        .breadcrumb {
            background-color: #ecf0f1;
            padding: 10px 0;
            margin-bottom: 20px;
        }
        .breadcrumb-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        .breadcrumb a {
            color: #3498db;
            text-decoration: none;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 0 20px;
        }
        .booking-container {
            background: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .schedule-info {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 30px;
        }
        .schedule-info h3 {
            color: #2c3e50;
            margin-bottom: 15px;
        }
        .schedule-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
        }
        .detail-item {
            color: #7f8c8d;
        }
        .detail-item strong {
            color: #2c3e50;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #2c3e50;
            font-weight: bold;
        }
        .form-control {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
        }
        .form-control:focus {
            outline: none;
            border-color: #3498db;
        }
        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
        .btn-primary {
            background-color: #3498db;
            color: white;
        }
        .btn-primary:hover {
            background-color: #2980b9;
        }
        .btn-secondary {
            background-color: #95a5a6;
            color: white;
        }
        .btn-secondary:hover {
            background-color: #7f8c8d;
        }
        .form-actions {
            text-align: center;
            margin-top: 30px;
        }
        .form-actions .btn {
            margin: 0 10px;
        }
        .error-message {
            color: #e74c3c;
            background-color: #fdf2f2;
            border: 1px solid #fecaca;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .required {
            color: #e74c3c;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <h1>医疗预约系统</h1>
            <c:choose>
                <c:when test="${not empty sessionScope.loginUser}">
                    <span>欢迎，${sessionScope.loginUser.username}</span>
                </c:when>
                <c:otherwise>
                    <a href="auth/login" class="btn btn-primary">登录</a>
                    <a href="auth/register" class="btn btn-secondary" style="margin-left: 10px;">注册</a>
                </c:otherwise>
            </c:choose>
        </div>
    </div>

    <div class="breadcrumb">
        <div class="breadcrumb-content">
            <a href="frontend/index">首页</a> > 
            <a href="frontend/departments?hospitalId=${visit.department.hospitalId}">${visit.department.hospital.hospitalName}</a> > 
            <a href="frontend/schedules?deptId=${visit.department.deptId}">${visit.department.deptName}</a> > 
            <span>预约挂号</span>
        </div>
    </div>

    <div class="container">
        <div class="booking-container">
            <h2>预约挂号</h2>

            <!-- 错误提示 -->
            <c:if test="${not empty error}">
                <div class="error-message">
                    ${error}
                </div>
            </c:if>

            <div class="schedule-info">
                <h3>排班信息</h3>
                <div class="schedule-details">
                    <div class="detail-item">
                        <strong>医生：</strong>${visit.doctorName}
                    </div>
                    <div class="detail-item">
                        <strong>科室：</strong>${visit.department.deptName}
                    </div>
                    <div class="detail-item">
                        <strong>医院：</strong>${visit.department.hospital.hospitalName}
                    </div>
                    <div class="detail-item">
                        <strong>日期：</strong>${visit.visitDate}
                    </div>
                    <div class="detail-item">
                        <strong>时段：</strong>${visit.timeSlot}
                    </div>
                    <div class="detail-item">
                        <strong>剩余名额：</strong>${visit.maxNum - visit.usedNum}
                    </div>
                </div>
            </div>

            <form action="frontend/book" method="post">
                <input type="hidden" name="visitId" value="${visit.visitId}">
                
                <div class="form-group">
                    <label for="patientName">患者姓名 <span class="required">*</span></label>
                    <input type="text" id="patientName" name="patientName" class="form-control" required>
                </div>

                <div class="form-group">
                    <label for="patientPhone">联系电话 <span class="required">*</span></label>
                    <input type="tel" id="patientPhone" name="patientPhone" class="form-control" required>
                </div>

                <div class="form-group">
                    <label for="symptoms">病情描述</label>
                    <textarea id="symptoms" name="symptoms" class="form-control" rows="4" 
                              placeholder="请简要描述您的症状，方便医生了解情况"></textarea>
                </div>

                <div class="form-actions">
                    <a href="frontend/schedules?deptId=${visit.department.deptId}" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">确认预约</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        // 表单验证
        document.querySelector('form').addEventListener('submit', function(e) {
            const patientName = document.getElementById('patientName').value.trim();
            const patientPhone = document.getElementById('patientPhone').value.trim();
            
            if (!patientName) {
                alert('请输入患者姓名');
                e.preventDefault();
                return;
            }
            
            if (!patientPhone) {
                alert('请输入联系电话');
                e.preventDefault();
                return;
            }
            
            // 简单的手机号验证
            const phoneRegex = /^1[3-9]\d{9}$/;
            if (!phoneRegex.test(patientPhone)) {
                alert('请输入正确的手机号');
                e.preventDefault();
                return;
            }
        });
    </script>
</body>
</html>
